# from public import method
# from rest_framework import status as status_code
# from rest_framework.request import Request
from django.conf import settings
# from django.http import JsonResponse, HttpResponse
# import requests
# import re
# from public import dbs
import os


class DatabaseMiddleware:

    def process_request(self, request):
        # print('slkdlsajlskad')
        if os.name != "nt":
            settings.DATABASES['default'].update({'NAME': "db_platform"})
        else:
            settings.DATABASES['default'].update({'NAME': "db_MC"})
        if request.GET.get('tenant_id') or request.POST.get("tenant_id"):
            # print('ddddd')
            data = request.GET.get("tenant_id") or request.POST.get("tenant_id")
            # print("aaaaa",data)
            db_name = "db_" + data
            # print(db_name)
            settings.DATABASES['default'].update({'NAME': db_name})